package q1221_balancedStringSplit;

public class Solution_2 {
    public int balancedStringSplit(String s) {
        int ans = 0, diff = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == 'L') {
                ++diff;
            } else {
                --diff;
            }
            if (diff == 0) ++ans;
        }
        return ans;
    }
}
